/*
    This file is a native implementation of the thread_id.c file.
    It is used to get the current thread ID as a 64-bit integer.

    LICENSE: MIT
    AUTHOR: support@tongyuan.cc
*/

#include <stdint.h>

#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#elif defined(__APPLE__)
#include <pthread.h>
#else
#define _GNU_SOURCE
#include <unistd.h>
#endif

#ifdef _WIN32
__declspec(dllexport)
#else
__attribute__((visibility("default")))
#endif
    uint64_t get_current_thread_id(void) {
#ifdef _WIN32
  // GetCurrentThreadId() is available since Windows XP
  return (uint64_t)GetCurrentThreadId();
#elif defined(__APPLE__)
  uint64_t tid;
  pthread_threadid_np(NULL, &tid);
  return tid;
#else
  // glibc has exposed gettid() since 2.30
  return gettid();
#endif
}
